import org.junit.Assert;
import org.junit.Test;

import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.*;

public class NGuessNumberTest {

    @Test
    public void generateAnswer() {
        NGuessNumber nGuessNumber=new NGuessNumber();
        List<Integer> list=nGuessNumber.generateAnswer();
        //答案数字数量是否为4
        Assert.assertEquals(list.size(),4);
        //是否无重复数字
        Assert.assertEquals(list.size(),list.stream().distinct().collect(Collectors.toList()).size());
        //数字是否都在0-9之间
        Assert.assertEquals(list.size(),list.stream().filter(num->num>=0&&num<=9).collect(Collectors.toList()).size());
    }

    @Test
    public void getPlayerInput() {
        NGuessNumber nGuessNumber=new NGuessNumber();
        List<Integer> list=nGuessNumber.getPlayerInput();
        Assert.assertEquals(list.size(),4);
    }

    @Test
    public void compareGuessAnswer() {
        NGuessNumber nGuessNumber = new NGuessNumber();
        int a = 0, b = 0;
        List<Integer> daan = nGuessNumber.generateAnswer();
        List<Integer> sc =  nGuessNumber.getPlayerInput();
        for (int i = 0; i < daan.size(); i++) {
            if (daan.get(i) == sc.get(i)) {
                b++;
            }
            for (int j = 0; j < sc.size(); j++) {
                if (daan.get(i) == sc.get(j)) {
                    a++;
                }
            }
        }
        String s=a + "A" + b + "B";
        Assert.assertEquals(s,nGuessNumber.compareGuessAnswer());

    }

    @Test
    public void isWin() {
        NGuessNumber nGuessNumber = new NGuessNumber();
        if(nGuessNumber.isWin()==true){
            assertEquals(true,nGuessNumber.isWin());
            System.out.println("根据提示信息中A的数量判断玩家是否获胜");
        }else if(nGuessNumber.isWin()==false){
            assertEquals(false,nGuessNumber.isWin());
            System.out.println("根据提示信息中A的数量判断玩家是否获胜");
        }else{
            assertEquals(true,nGuessNumber.isWin());
            assertEquals(false,nGuessNumber.isWin());
            System.out.println("根据提示信息中A的数量判断玩家是否获胜");
        }
    }
}